/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.object;

import net.worlds.WorldsException;
import net.worlds.Main;
import se.krka.kahlua.vm.JavaFunction;
import se.krka.kahlua.vm.LuaCallFrame;


public class Players extends GameObject {
    public Players() throws WorldsException
    {
        super("Players");
        addFunction("setLocalPlayer", new JavaFunction()
        {

            public int call(LuaCallFrame callFrame, int nArguments) {
                try {
                    if (nArguments != 2) {
                        throw new RuntimeException("setLocalPlayer() requires 1 argument");
                    }
                    if (callFrame.get(1) instanceof Player) {
                        Main.setLocalPlayer((Player) callFrame.get(1));
                    } else {
                        throw new RuntimeException("Argument to setLocalPlayer() must be a player");
                    }
                } catch (WorldsException ex) {
                    throw new RuntimeException(ex);
                }
                return 0;
            }

        });
        //x_;
    }
}
